package cn.itcast.order.service;


import cn.itcast.feign.clients.UserClient;
import cn.itcast.feign.pojos.User;
import cn.itcast.order.mapper.OrderMapper;
import cn.itcast.order.pojo.Order;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class OrderService {

    @Autowired
    private OrderMapper orderMapper;

//    @Autowired
//    private RestTemplate restTemplate;

    @Autowired
    private UserClient userClient;

    public Order queryOrderById(Long orderId) {
        // 1.查询订单
        Order order = orderMapper.findById(orderId);

        Long userId = order.getUserId();//用户id

        //2.调用用户服务的http接口，获取用户数据
//        String url = "http://userservice/user/"+userId;
//        User user = restTemplate.getForObject(url, User.class);
        User user = userClient.queryById(userId);

        //3.设置订单的用户数据
        order.setUser(user);

        // 4.返回
        return order;
    }
}
